package com.shhm.admin.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.admin.mapper.UniversityMapper;
import com.shhm.admin.service.UniversityService;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.admin.UniversityEntity;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/17 下午4:51
 */
@Service
public class UniversityServiceImpl implements UniversityService {

    @Resource
    private UniversityMapper universityMapper;

    // 创建高校信息
    @Override
    public AjaxResultPlus createUniversity(UniversityEntity entity) {
        entity.createLocalDateTime();
        return ResponseUtil.sqlExeIsSuccess(universityMapper.insert(entity));
    }

    // 更新高校信息
    @Override
    public AjaxResultPlus updateUniversity(UniversityEntity dto) {
        return ResponseUtil.sqlExeIsSuccess(universityMapper.updateById(dto));
    }

    // 获取高校信息（通过ID）
    @Override
    public AjaxResultPlus getUniversityById(Long universityId) {
        UniversityEntity entity = universityMapper.selectById(universityId);
        if (entity == null) {
            throw new RuntimeException("高校信息不存在");
        }
        return AjaxResultPlus.success(entity,true);
    }

    // 删除高校信息（逻辑删除）
    @Override
    public AjaxResultPlus deleteUniversity(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(universityMapper.deleteByIds(list));
    }

    // 搜索高校信息
    @Override
    public AjaxResultPlus searchUniversities(UniversityEntity dto) {
        List<UniversityEntity> entities = universityMapper.search(dto);
        return AjaxResultPlus.success(entities,false);
    }

    @Override
    public AjaxResultPlus pageList(Integer pageNum, Integer pageSize, Integer isPage, HttpServletRequest request) {
        return AjaxResultPlus.success(universityMapper.selectPage(new PageDTO<>(pageNum, pageSize),null),false);
    }
}

